// Lindsay Gilmour
// Adam Lusch
// Dan Niceswanger
//
// Computer Graphics Project 1:
// Asteroids!
// A Tribute

#ifndef PHYSICS_WORLD_H
#define PHYSICS_WORLD_H

#include <list>
#include <set>
#include <map>
#include <GL/glut.h>
#include <cmath>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;

#include <Box2D.h>
#include "Thing.h"
#include "Asteroid.h"
#include "Ship.h"
#include "Bullet.h"
#include "AlienBullet.h"
#include "Ufo.h"
#include "Particle.h"
#include "Render.h"
#include "CollisionHandler.h"

class CollisionHandler;

class PhysicsWorld
{
	public:

		static const int32 ALIEN_TIME = 5 * 60;
		static const int32 ALIEN_SHOOT_MIN = 30;
		static const int32 ALIEN_SHOOT_MAX = 120;
	
		PhysicsWorld();
		~PhysicsWorld();
		
		void addAsteroid(float32);

		void startGame();
		void splashScreen();
		
		void setupLevel();
		bool spawnPlayer();
		void spawnBullet();

		void init();

		void setViewable(float32, float32, float32, float32);

		bool isPlaying() const;
		bool isScoring() const;
		
		void step(float32, int32, int32*);

		void getScores();
		void saveScore();
		void addLetter(unsigned char);

	private:
		
		void moveOffscreenThing(Thing*);
		void setUpLifeList();
		void drawLives();
		void drawText(float32, float32, string);
		void drawTitle();
		void drawScores();

		void handleAchievements();

		void spawnUfoBullet();
		void spawnAlien();

		int32 score;
		int32 lives;
		string name;
		
		b2AABB worldAABB;
		bool doSleep;
		b2World* world;

		float32 left, right, bottom, top;

		DebugDraw debug;
		list<Thing*> things;
		list<Particle*> particles;
		Ship* ship;
		Ufo* ufo;
		
		static const int32 k_maxCount = 10;
		b2Shape* shapes[k_maxCount];
		b2AABB tester;
		CollisionHandler* collisions;

		GLuint lifeList;

		int32 level;
		int32 numAsteroids;
		static int32 bulletsFired;
		static int32 bulletsHit;

		static const int32 extraLifeBonus = 150;
		static const int32 levelBonus = 200;
		static const int32 diplomatBonus = 500;
		static const int32 predatorBonus = 750;
		static const int32 marksmanBonus = 1000;
		static const int32 displayTimer = 250;
		list<string> achievements;
		int32 messageTimer;

		multimap <int, string, greater<int> > highScores;

		bool playing;
		bool dead;
		bool scoring;
		bool showingScores;
		bool gameOver;
		
		int32 alienTimeout;
		int32 alienShootTimeout;
		int32 alienKills;
};


#endif
